using System.Collections.Generic;
using System.Linq;

namespace Vibstudio.X4NET.Collections
{
    public class KeyValuePairCollection<T> : List<T> where T : KeyValuePair
    {
        public bool ContainsKey(string key)
        {
            return this.Any(pair => pair.Key == key);
        }

        public bool ContainsValue(string value)
        {
            return this.Any(pair => pair.Value == value);
        }

        public string GetFirstValue(string key)
        {
            string value = string.Empty;

            foreach (T pair in this)
            {
                if (pair.Key == key)
                {
                    value = pair.Value;
                    break;
                }
            }

            return value;
        }

        public List<string> GetValues(string key)
        {
            return (from pair in this where pair.Key == key select pair.Value).ToList();
        }

        public string GetUniqueValue(string key, int id)
        {
            string result = string.Empty;

            foreach (T pair in this)
            {
                if (pair.Key == key && pair.ID == id) result = pair.Value;
            }

            return result;
        }
    }
};